import sun.swing.StringUIClientPropertyKey;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—07—20
 * Time: 8:59
 */ public class Demo01 {
    public static void main1(String[] args) {
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        int[] array = {80,30,48,60,90,56};
        for (int i = 0; i < array.length; i++) {
            binarySearchTree.insert(array[i]);
        }
        System.out.println("============");
        binarySearchTree.remove(30);
        binarySearchTree.inorder(binarySearchTree.root);

    }

    public static void main2(String[] args) {
        //key-value
        Map<String,Integer> map1 = new TreeMap<>();
        Map<String,Integer> map2 = new HashMap<>();

        //key
        Set<String> set1 = new TreeSet<>();
        Set<String> set2 = new HashSet<>();
    }

    public static void main3(String[] args) {
        Map<String,Integer> map1 = new TreeMap<>();
        map1.put("javase",20);
        map1.put("javaee",13);
        map1.put("javaweb",6);
 /*     map1.put("javase",66);
        System.out.println(map1.get("javase"));
        System.out.println(map1.get("c++"));
        System.out.println(map1.getOrDefault("javaee",45));*/
/*        map1.remove("javaee");
        System.out.println(map1);*/

/*        Set<String> set = map1.keySet();
        System.out.println(set);*/

/*        Collection<Integer> collection= map1.values();
        System.out.println(collection);*/

        Set<Map.Entry<String,Integer>> entrySet = map1.entrySet();
        for (Map.Entry<String,Integer> entry : entrySet) {
            System.out.println("key: " + entry.getKey() +
                    " val: " + entry.getValue());
        }
    }

    public static void main4(String[] args) {
        Map<String,Integer> map1 = new HashMap<>();
        map1.put("javase",20);
        map1.put("javaee",13);
        map1.put("javaweb",6);
        System.out.println("打印HashMap:" +map1);
        Set<Map.Entry<String,Integer>> entrySet = map1.entrySet();
        for (Map.Entry<String,Integer> entry : entrySet) {
            System.out.println("key: " + entry.getKey() +
                    " val: " + entry.getValue());
        }
    }

    public static void main5(String[] args) {
        Set<String> set = new TreeSet<>();
        set.add("qwe");
        set.add("asd");
        set.add("qwe");
        System.out.println(set);
    }

    public static void main(String[] args) {
        int[] array = new int[10_0000];
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(5_000);
        }
        fun1(array);
        fun2(array);
        fun3(array);
    }

    //1.10W个数字，去掉重复的用 Hashset
    public static void fun1(int[] array) {
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            set.add(array[i]);
        }
        System.out.println(set);
    }
    //2.10W个数字，打印第一个出现重复的
    public static int fun2(int[] array) {
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            if(!set.contains(array[i])) {
                set.add(array[i]);
            }else {
                return array[i];
            }
        }
        System.out.println(set);
        return -1;
    }
    //3.10W个数字，打印每个数字出现和每个数字对应出现的次数
    public static void fun3(int[] array) {
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < array.length; i++) {
           int key = array[i];
           if(map.get(key) == null) {
               map.put(key,1);
           }else {
               int val = map.get(key);
               map.put(key, val + 1);
           }
        }
    }
 }
